use config::Config;
use serde::Deserialize;

#[derive(Debug, Deserialize)]
pub struct Settings {
    pub option: Option,
    pub window: Window,
}
#[derive(Debug, Deserialize)]
pub struct Option {
    #[serde(default = "default_entry")]
    pub entry: String, // 默认值为空字符串
}
#[derive(Debug, Deserialize)]
pub struct Window {
    #[serde(default = "default_width")]
    pub width: u16, // 默认值为 0
    #[serde(default = "default_height")]
    pub height: u16, // 默认值为 0
}

fn default_entry() -> String {
    "system".to_string()
}

fn default_width() -> u16 {
    1024
}

fn default_height() -> u16 {
    768
}
pub fn load_config() -> Settings {
    let config = Config::builder()
        .add_source(config::File::with_name("config").required(false))
        .build()
        .unwrap()
        .try_deserialize::<Settings>()
        .unwrap();
    let settings: Settings = config.try_into().unwrap();
    settings
}
